home *** CD-ROM | disk | FTP | other *** search
- /* viewdisp.c file - displays current page of file */
- #include "stdio.h"
- #include "cminor.h"
- #include "viewparm.h"
-
- #define TAB_WIDTH 8
- #define PAGE_WIDTH 80
- extern char filename[] ;
- extern long filesize ; /* size of file in bytes */
- extern long top_of_page ; /* file position of top of page */
- int row ; /* current line of page */
- int col ; /* current column of page */
-
- display_page()
- {
- int c ; /* hold the character here */
- int i ; /* counter for loop */
-
- move_to(top_of_page) ; /* start at top of page */
- /* write a header line */
- printf("\n FILE - %s POSITION - %1d FILE SIZE - %1d \n",
- filename,top_of_page,filesize);
-
- /* write a border line of dashes*/
- for( i=1 ; i < 80 ; i = i + 1 )
- { putchar('-') ; }
-
- /* get chars from file until we've written (PAGE_SIZE) lines */
- /* or we've reached the end of the file */
- row = 1 ; /* starting row and column values*/
- col = 1 ;
- c = get_next_char() ;
- while( ( row <= PAGE_SIZE ) && ( c != EOF_MARK ) )
- { /* write till end of page or file*/
- disp_char(c) ; /* display current character */
- c = get_next_char() ; /* and get another one */
- }
- while( row <= PAGE_SIZE ) /* pad out page if eof reached */
- { putchar('\n'); row = row + 1 ; }
-
- for( i=1 ; i < 80 ; i=i+1 ) /* write a border line of dashes */
- { putchar('-') ; }
- }
-
-
- int disp_char(c) /* display one character */
- /* and update row and column */
- int c ; /* value of char to write */
- {
- /* classify the character and handle accordingly */
-
- if( isgraphic(c) )
- { putchar(c) ; /* display ASCII graphic char */
- col = col + 1 ; /* advansc column number */
- if( col > PAGE_WIDTH ) /* check wrap-around */
- { row = row + 1 ; /* yes - advance row number */
- col = 1 ; /* set col to begining of line */
- }
- }
- else if( c == END_LINE )
- { putchar('\n') ; /* end_line char - force new line*/
- row = row + 1 ; /* advance row number */
- col = 1 ; /* set column to first col */
- }
- else if( c == '\t' )
- {
- do /* tab and expand it */
- { putchar(' ') ; /* print spaces */
- col = col + 1 ; /* and advance column number */
- if( col > PAGE_WIDTH ) /* check wrap-around */
- { row = row + 1 ;
- col = 1 ;
- }
- } while( ( col % TAB_WIDTH ) != 1 ) ; /* until tab stop */
- }
- }